import {
	HTTP_REQUEST_URL,
	IMAGE_URL,
	IM_URL,
	PERFIX,
	kfs,
	LOCALE
} from "@/config/app"
import Vue from 'vue'
//国际化
import RU from '@/lang/ru-RU.json'
import CN from '@/lang/zh-CN.json'
import VueI18n from 'vue-i18n'
const messages = {
	'ru': RU,
	'zh': CN,
}
let i18nConfig = {
	locale: LOCALE, // 获取已设置的语言
	messages,
	silentTranslationWarn: true, // 去除国际化警告
}
Vue.use(VueI18n)
let i18n = new VueI18n(i18nConfig)
Vue.config.productionTip = false
Vue.prototype._i18n = i18n
let app2 = new Vue({
	i18n
})
const getTodayDate = () => {
	const date = new Date();
	return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`
}

export default async (vm) => {
	return new Promise((resolve, reject) => {
		const userAuth = uni.getStorageSync("userAuth");

		//俄罗斯直接通过 不需要是VIP
		if (uni.getStorageSync("lang") === "ru") {
			resolve(true)
		}

		//未开启允许游客聊天开关并且当前用户是游客
		if (!userAuth.chat_flag && userAuth.level < 1) {
			uni.showModal({
				content: app2.$i18n.t('您的权限不足哦!请联系工作人员!'),
				showCancel: false,
				confirmText: app2.$i18n.t('是'),
			})
			resolve(false)
		}
		//游客并且是国语
		if (userAuth.level < 1 && uni.getStorageSync("lang") === "zh") {
			//当前可聊天次数小于最大次数
			if (userAuth.chat_count <= userAuth.chat_max) {
				if (!uni.getStorageSync("chatVisitDate")) {
					uni.showModal({
						title: app2.$i18n.t('系统提示'),
						content: `${app2.$i18n.t('可使用即时聊天次数')}(${userAuth.chat_count}/${userAuth.chat_max}),${app2.$i18n.t('点击关闭将不再提醒')}`,
						confirmText: `${app2.$i18n.t('我知道了')}`,
						cancelText: `${app2.$i18n.t('关闭')}`,
						success: e => {
							if (e.cancel) {
								uni.setStorageSync("chatVisitDate", getTodayDate())
							}
							resolve(true)
						}
					})
				}
				//选择了当日不提示
				else {
					resolve(true)
				}
			} else {
				//VIP窗口 Else 系统窗
				if (userAuth.vip) {
					let pages = getCurrentPages();
					let currentPage = pages[pages.length - 1];
					console.log(currentPage);
					currentPage.vipShow = true
					currentPage.$vm.vipShow = true;
				} else {
					uni.showModal({
						content: app2.$i18n.t('您的权限不足哦!请联系工作人员!'),
						showCancel: false,
						confirmText: app2.$i18n.t('是'),
					})
				}
				resolve(false)
			}
		} else {
			resolve(true)
		}
	})
}